# @Desc    : do what 
# @Author  : meihongliang  
# @Time    : 2025-03-22 14:32
from apscheduler.schedulers.blocking import BlockingScheduler
from datetime import datetime, timedelta

from schedule import life_schedule


# 自定义方法
def my_custom_task():
    print(f"执行任务：当前时间是 {datetime.now()}")


# 判断是否是每月的最后一天
def is_last_day_of_month():
    today = datetime.now()
    # 获取下一天
    next_day = today + timedelta(days=1)
    # 如果下一天是下个月的第一天，则今天是最后一天
    return today.month != next_day.month


# 定时任务调度器
scheduler = BlockingScheduler()


# 添加定时任务
@scheduler.scheduled_job('cron', day='*', hour=12, minute=0)  # 每天中午 12 点检查
def every_day():
    if is_last_day_of_month():
        my_custom_task()


@scheduler.scheduled_job('cron', minute='*')
def every_minute():
    print(f"每分钟执行任务：当前时间是 {datetime.now()}")


@scheduler.scheduled_job('interval', seconds=10)
def every_10_seconds():
    print(f"每10秒执行任务：当前时间是 {datetime.now()}")
    life_schedule.check_item()


# 启动调度器
if __name__ == "__main__":
    print(f"定时任务已启动...{datetime.now()}")
    try:
        print(f'\t{datetime.now()}')
        scheduler.start()
    except (KeyboardInterrupt, SystemExit):
        print("定时任务已停止...")
